#ifndef MONITOR_H
#define MONITOR_H

#include <QApplication>
#include <QWidget>
#include <QTime>

namespace Ui {
class Monitor;
}

class QTimer;
class OsgWidget;
class LogDialog;
class LogFullDialog;
class PlotTemperature;
class PlotPressure;
class PlotO2;
class PlotTemperatureMonitor;

enum UserId
{
    ADMIN=0,
    ENGINEER=1,
    OPERATOR=2,
    GUEST=3,
};

enum Interface
{
    PAGE_MONITOR = 0,
    PAGE_DATASTATISTICS,
    PAGE_ABNORMALSTATISTICS,
    PAGE_SYSTEMLOG,
    PAGE_USERMANAGE,
    PAGE_SYSTEMSET,
    PAGE_MAPPING,
    PAGE_TASKMANAGE,
    PAGE_FORVIEWS,
    PAGE_DEBUG,
};

class Monitor : public QWidget
{
    Q_OBJECT

public:
    explicit Monitor(QWidget *parent = nullptr);
    ~Monitor();
    void init();

    bool loadSysConfig();

private:
    void changeCurrentRole(UserId roleID);
    void GuestPermissions();
    void OperatorPermissions();
    void EngineerPermissions();
    void AdminPermissions();
    void RoleLogoutAndTransToGuest();
    void RoleLogin();

    void printProtect();
    void printEnd();

signals:
    void initApp();

private slots:
    void displayCurrentTime();

    void on_exit();
    void on_laserTest();
    void on_about();

    void onCliLaberSelectStateChanged(int);

    void on_updatePermissions(QString account);

    void onSysConfigChanged(int);
    void onSysConfigChanged(double);
    void onSysConfigChanged(const QString &);
    void onSysConfigChangedLineEdit(const QString &);

    void on_dataSynchronous(QMap<int,float>);

    void on_updataCliShow(int);

    void on_printFinished();

    void on_toolButton_load_clicked();

    void on_tB_print_clicked();

    void on_tB_preparation_clicked();

    void on_tB_monitor_clicked();

    void on_tB_Precodes_clicked();

    void on_tB_log_clicked();

    void on_toolButton_logOn_clicked();

    void on_pushButton_2D_clicked();

    void on_pushButton_3D_clicked();

    void on_pushButton_backHome_clicked();

    void on_pushButton_open_clicked();

    void on_pushButton_save_clicked();

    void on_pushButton_Log_clicked();

    void on_toolButton_set_clicked();

    void on_toolButton_setServoJog1um_clicked();

    void on_toolButton_setServoJog10um_clicked();

    void on_toolButton_setServoJog100um_clicked();

    void on_toolButton_setServoJog1mm_clicked();

    void on_toolButton_ServoAJogUp_clicked();

    void on_toolButton_ServoAJogDown_clicked();

    void on_toolButton_ServoBJogUp_clicked();

    void on_toolButton_ServoBJogDown_clicked();

    void on_pushButton_ServoAPosMove_clicked();

    void on_pushButton_ServoAGo0_clicked();

    void on_pushButton_ServoASet0_clicked();

    void on_pushButton_ServoBPosMove_clicked();

    void on_pushButton_ServoBGo0_clicked();

    void on_pushButton_ServoBSet0_clicked();

    void on_pushButton_scraperPosMove_clicked();

    void on_pushButton_scraperGo0_clicked();

    void on_pushButton_scraperSet0_clicked();

    void on_pushButton_servoPowderEnable_clicked();

    void on_pushButton_servoFeedEnable_clicked();

    void on_pushButton_servoManufactureEnable_clicked();

    void on_pushButton_servoManufactureStop_clicked();

    void on_pushButton_servoFeedStop_clicked();

    void on_pushButton_scraperPosStop_clicked();  

    void on_pushButton_servoManufactureReset_clicked();

    void on_pushButton_servoFeedReset_clicked();

    void on_pushButton_servoPowderReset_clicked();

    void on_pushButton_StartPreheating_clicked(bool checked);

    void on_pushButton_alarmReset_clicked();

    void on_pushButton_PrintStart_clicked();

    void on_pushButton_PrintPaused_clicked();

    void on_pushButton_PrintTermination_clicked();

    void on_pushButton_GasWashingStart_clicked(bool checked);

    void on_pushButton_SetoxygenContent_clicked();

    void on_pushButton_SetoxygenContentMax_clicked();

    void on_pushButton_SetyAirRate_clicked();

    void on_pushButton_SetCabinPressureMax_clicked();

    void on_pushButton_SetCabinPressureMin_clicked();

    void on_pushButton_backblowingClean_clicked(bool checked);

    void on_pushButton_PipelineCleaningStart_clicked(bool checked); 

    void on_horizontalSlider_layer_valueChanged(int value);

    void on_pushButton_layerSubtraction_clicked();

    void on_pushButton_layerAdd_clicked();

    void on_toolButton_deviceStatus_clicked();

    void on_pushButton_oneReconnection_clicked();

    void on_pushButton_alarmResetAll_clicked();    

    void on_pushButton_applyParaModify_clicked();

    void on_pushButton_undoParaModify_clicked();

    void on_pushButton_adjBaseTemp_clicked();

    void on_pushButton_adjPowerRatio_clicked();

    void on_pushButton_adjLoopFanSpeed_clicked();

    void on_pushButton_adjLaserPowerRatio_clicked();

    void on_pushButton_adjScraperSpeedRatio_clicked();

    void on_pushButton_adjLaserSpeedRatio_clicked();

    void on_pushButton_scraperMoveLeft_clicked();

    void on_pushButton_scraperMoveRight_clicked();

    void on_radioButton_spreadingOK_clicked(bool checked);

    void on_pushButton_adjSelectPrintLayer_clicked();

    void on_radioButton_CabinLighting_clicked(bool checked);  

    void on_toolButton_setServoJog25um_clicked();

private:
    Ui::Monitor *ui;
    QTimer *dateTime_;

    OsgWidget* osgWidget_{ nullptr};
    OsgWidget* osgSet_{ nullptr};

    PlotTemperature* plotTemp_{nullptr};
    PlotPressure* plotPressure_{nullptr};
    PlotO2* plotO2_{nullptr};

    PlotTemperature* plotTempM_{nullptr};
    PlotPressure* plotPressureM_{nullptr};
    PlotO2* plotO2M_{nullptr};

    PlotTemperatureMonitor* plotMicroPressure_{nullptr};

    LogDialog* logDialogMini;
    LogFullDialog* logDialogFull;

    QString role{"guest"};
    const QMap<QString,UserId> UserMap{
        {"admin", ADMIN},
        {"engineer", ENGINEER},
        {"operator", OPERATOR},
        {"guest", GUEST}};

    int timeTick_S{0};
    qint64 startTimestamp{0};

    QTime startPrintTime;


};

#endif // MONITOR_H
